#!/bin/bash
# TCP客户端 - 测试环境
# 连接到ECS上的测试服务器

set -e

ECS_HOST="47.106.214.252"
TCP_PORT="8889"

echo "=========================================="
echo "  PokerMind TCP客户端 - 测试环境"
echo "=========================================="
echo ""
echo "服务器地址: $ECS_HOST:$TCP_PORT"
echo "模式: 交互式流程"
echo "功能: 完整扑克手牌流程测试"
echo ""

# 检查服务器连通性
echo "检查服务器连通性..."
if nc -z $ECS_HOST $TCP_PORT 2>/dev/null; then
  echo "✓ 服务器在线"
else
  echo "✗ 服务器不可达"
  echo ""
  echo "请确认:"
  echo "  1. ECS服务器已启动"
  echo "  2. TCP服务在运行: ssh -i ~/.ssh/pokermind-ai-test.pem root@$ECS_HOST 'ps aux | grep pokermind-tcp'"
  echo "  3. 本地可以访问ECS (ping $ECS_HOST)"
  exit 1
fi

echo ""
echo "开始交互式测试..."
echo ""

# API Key配置（默认测试Key）
API_KEY="pk_test_demo00000000000000000000000000000000"
echo "API Key: ${API_KEY:0:12}***${API_KEY: -4}"
echo ""

# 启动客户端
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

mvn exec:java \
  -Dexec.mainClass="com.pokermind.dse.tcp.TcpClientMain" \
  -Dexec.args="$ECS_HOST $TCP_PORT $API_KEY" \
  -q
